package com.klun.aop;

import com.klun.aop.speak.SpeakSomething;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class Application {
    @Autowired
    private SpeakSomething personSpring;
    public static void main(String[] args) {

        SpringApplication.run(Application.class, args);
    }

    @Bean
    public CommandLineRunner commandLineRunner(ApplicationContext ctx) {

        return args -> {
            // spring aop
            System.out.println("******** spring aop ******** ");
            personSpring.sayHi();
            personSpring.sayBye();
            System.exit(0);
        };
    }

//    ******** jdk dynamic proxy ********
//
//    begin monitor..                               MethodMonitor

//    Hi!!                                          SpeakSomethingImpl
//    end monitor..                                 MethodMonitor
//    Method: sayHi, execution time: 32 milliseconds. SpeakSomethingImpl
//    begin monitor..
//    Bye!!
//    end monitor..
//
//    Method: sayBye, execution time: 22 milliseconds.
}
